# -*- coding: utf-8 -*-
# @Time    : 2021/3/17 11:34
# @Author  : wenyao
# @Email   : 343292019@qq.com
# @File    : 02.字符串.py

# a='hello'
# b="world"
# c="""
#  a
#  b
#  c
# """
# print(a)
# print(b)
# print(c)

#属性查看
#dir()
#属性使用
#变量名.属性名

#特殊标记r  表示不转义，作为原始字符输出
# >>> print("a\n b")
# a
# b
# >>> print(r"a\n b")
# a\n b

# >>> a="bb\"c"
# >>> a
# 'bb"c'
# >>> a='bb"c'
# >>> print(a)
# bb"c
# >>> a="bb'c"
# >>> print(a)
# bb'c

#切片
#str[start:end:step]
#step 默认是1
#如果step为正，表示从左至右截取，如果step为负，表示从右至左截取
#如果step为正，start默认就是0，end默认就是到字符串的结尾
#如果step为负，start默认就是-1，end默认是就是字符串的开始
# str1="abcdefghijklmn"
# print(str1[1:6:2])
# print(str1[::-1])
# print(str1[:8:3])
# print(str1[2:-4:-2])
# print(str1[:10:2])
# print(str1[6::2])
# print(str1[-3::-3])

###############################字符串常用方法属性######################
#判断系列is########
#True  为真
#False 为假
# str1 = "123456"
# str2 = "abcedf"
# str3 = "123一二三"
# str4 = "Sanchuang Tonele"
# str5 = "HELLOWORLD"
#
# print("判断数字:",str1.isdigit())
# print("判断数字:",str3.isdigit())
# print("判断数字:",str3.isnumeric())
#
# print("判断字母:",str2.isalpha())
# print("判断字母:",str4.isalpha())
#
# print("判断小写:",str2.islower())
# print("判断大写:",str5.isupper())
#
# print("判断标题：",str4.istitle())
#
# print("判断开头:",str1.startswith("abc"))
# print("判断开头:",str2.startswith("abc"))
# print("判断结尾:",str1.endswith("6"))


#查找统计类######
# a = "lsjefw2e4rfsf"
# print("查找字符串的长度：",len(a))
# print("统计子串出现的次数：",a.count("s"))
# #index 没有找到，会抛出异常
# print("查找子串第一次出现的位置（下标）:",a.index("s"))
# #find  没有找到，会返回-1
# print("查找子串第一次出现的位置（下标）:",a.find("s"))

#转换#########
msg = "i Am Ok"

#upper大写
print(msg.upper())
#lower小写
print(msg.lower())
#单词首字符大写
print(msg.title())
#大小写互换
print(msg.swapcase())
#
#字符串切割
msg1="sanchuang1:x:1002:1002::/home/sanchuang1:/bin/bash"
#以冒号切割字符串
msg1_list = msg1.split(":")
print(msg1_list)
#将列表中的字符串拼接在一起，并且以#号分隔
print("#".join(msg1_list))

#替换
msg2 = "ab*cd*ef**#cde"
msg2_list = msg2.split("*")
print("#".join(msg2_list))

print(msg2.replace("*","#"))

#去除首尾字符（默认空白）
msg3 = "#       sanch#uang# tong#le       "
print(msg3)
print(msg3.strip())
print(msg3.strip("#"))
#删除字符串中的#号键
print(msg3.replace("#",""))

#填充 (居中，左对齐，右对齐)
msg4 = "欢迎光临"
print(msg4.center(50,"*"))
print(msg4.ljust(50,"*"))
print(msg4.rjust(50,"*"))
